
#!/bin/perl
use strict;
use warnings;
use File::Basename;

print "Avaiable sessions:\n";
my @all_sessions = glob("~/gvim_sessions/*/Session.vim");
my $session_count = 0;
foreach (@all_sessions){
  printf "  %2s) %s\n", ++$session_count, basename(dirname $_);
}

print "Your choice: ";
while(<>){
  chomp;
  if((/^\s*\d+\s*$/) && ($_ <= $session_count) && ($_ >= 1)){
    print "Cleanning up session $all_sessions[$_-1]\n"; 
    my $dir_to_delete = dirname($all_sessions[$_-1]);
    unlink glob "$dir_to_delete/*";
    rmdir $dir_to_delete;
    print "Done^_^\n";
    print "Your choice: ";
  }else{
    print "Wrong input!\n";
    exit;
  }
}
